<template>
  <BasicTable @register="registerTable">
    <template #toolbar> </template>
    <template #action="{ record }">
      <TableAction
        :actions="[
          {
            icon: 'ant-design:file-search-outlined',
            onClick: handleSearch.bind(null, record),
            tooltip: '查询',
          },
        ]"
      />
    </template>
  </BasicTable>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useDrawer } from '/@/components/Drawer';
  import { columns, searchFormSchema } from './searchAuthorization.data';
  import { getQueryListWarrent } from '/@/api/reportForms/reportForms';
  import { useGo } from '/@/hooks/web/usePage';

  export default defineComponent({
    name: 'SearchAuthorization',
    components: { BasicTable, TableAction },
    setup() {
      const go = useGo();
      const [registerDrawer, { openDrawer }] = useDrawer();
      const [registerTable, { reload }] = useTable({
        title: '授权查询',
        api: getQueryListWarrent,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
          autoSubmitOnEnter: true,
        },
        searchInfo: {
          op: 'search',
        }, //额外的参数
        useSearchForm: false,
        showTableSetting: true,
        bordered: true,
        indexColumnProps: { width: 50 },
        showIndexColumn: true,
        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
      });

      //查询
      const handleSearch = (record) => {
        if (record.isScript) {
          go({
            path: '/searchTable',
            query: {
              id: record.id,
              title: record.name,
              cacheName: `searchTable${record.id}`,
            },
          });
        } else {
          go({
            path: '/searchTableNormal',
            query: {
              id: record.id,
              title: record.name,
              cacheName: `searchTableNormal${record.id}`,
            },
          });
        }
      };

      function handleSuccess() {
        reload();
      }

      return {
        registerTable,
        registerDrawer,
        handleSearch,
        handleSuccess,
      };
    },
  });
</script>
